package com.fancy.mobileschool.ui.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fancy.mobileschool.R;
import com.fancy.mobileschool.entity.YunFile;
import com.fancy.mobileschool.ui.YunFileActivity;
import com.fancy.mobileschool.ui.adapt.FileRecyclerViewAdapter;
import com.fancy.mobileschool.ui.widget.DividerItemDecoration;

import java.util.List;

/**
 * A fragment representing a list of Items.
 * <p/>
 * interface.
 */
public class MyYunFileFragment extends Fragment {

    private RecyclerView recyclerView;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_file_list, container, false);

        // Set the adapter
        if (view instanceof RecyclerView) {
            Context context = view.getContext();
            recyclerView = (RecyclerView) view;
            recyclerView.setLayoutManager(new LinearLayoutManager(context));
            recyclerView.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL_LIST));
        }
        return view;
    }

    @Override
    public void onStart() {
        super.onStart();
        ((YunFileActivity)getActivity()).getMyYunFiles();
    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p/>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface GetMyFile {

        void getMyYunFiles();

    }

    public void UpdateFilesList(List<YunFile> files) {
        if (files != null)
            recyclerView.setAdapter(new FileRecyclerViewAdapter(files));
    }

}
